package com.dasberg.gwt.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * Authentication Service.
 * @author mischa
 */
@RemoteServiceRelativePath("auth")
public interface AuthenticationService extends RemoteService {
    /**
     * Authenticate with the given username and password.
     * @param username The username.
     * @param password The password.
     * @return <code>true</code> if the system can authenticate with the given username and password,
     *         else <code>false</code>.
     */
    boolean authenticate(String username, String password);


    /** Deauthenticate by removing the AuthenticationToken from the session. */
    void deauthenticate();

    /**
     * Indicates if a user has the given role assigned.
     * @param role The role.
     * @return <code>true</code> if the user has the given role assigned, else <code>false</code>.
     */
    boolean isInRole(String role);

    /**
     * Indicates if the user is authenticated.
     * @return <code>true</code> if the user is authenticated, else <code>false</code>.
     */
    boolean isAuthenticated();

    /**
     * Gets the authenticated user.
     * @return user The user.
     */
    String getAuthenticatedUser();
}